package flc.ast.activity;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.blankj.utilcode.util.NumberUtils;
import com.stark.calculator.tax.constant.TaxConst;
import com.stark.calculator.tax.model.TaxCalBean;
import com.stark.calculator.tax.model.TaxCalRetBean;
import com.stark.calculator.tax.viewmodel.TaxCalRetViewModel;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.adapter.TaxKind1RetAdapter;
import flc.ast.databinding.ActivityTaxKind1RetBinding;
import stark.common.basic.base.BaseActivity;
import stark.common.basic.event.EventStatProxy;
import stark.common.basic.utils.StatusBarUtils;

public class TaxKind1RetActivity extends BaseActivity<TaxCalRetViewModel, ActivityTaxKind1RetBinding> {

    public static void start(Context context, TaxCalBean model) {
        Intent intent = new Intent(context, TaxKind1RetActivity.class);
        intent.putExtra(TaxConst.KEY_CAL_MODEL, model);
        context.startActivity(intent);
    }

    @Override
    protected TaxCalRetViewModel initViewModel() {
        return new ViewModelProvider(this).get(TaxCalRetViewModel.class);
    }

    @Override
    protected void showError(Object obj) {

    }

    @Override
    protected int onCreate() {
        return R.layout.activity_tax_kind1_ret;
    }

    @Override
    protected void initView() {
        StatusBarUtils.setStatusBarTranslate(this);
        mDataBinding.ivTaxKind1RetBack.setOnClickListener(v -> onBackPressed());
        mViewModel.getCalRet().observe(this, taxCalRetBean -> {
            updateUiContent(taxCalRetBean);
        });
    }

    @Override
    protected void initData() {
        TaxCalBean calBean = null;
        Intent intent = getIntent();
        if (intent != null) {
            calBean = (TaxCalBean) intent.getSerializableExtra(TaxConst.KEY_CAL_MODEL);
        }
        if (calBean != null) {
            mViewModel.calculate(calBean);
        }
    }

    private void updateUiContent(@NonNull TaxCalRetBean retBean) {
        //到手工资
        mDataBinding.tvTaxKin1Resul1.setText(NumberUtils.format(retBean.handSalary, 2));
        //税前工资
        mDataBinding.tvTaxKind1Gz.setText(NumberUtils.format(retBean.salaryBeforeTax, 2));
        //个人社保
        mDataBinding.tvTaxKind1Sb.setText(NumberUtils.format(retBean.personalSheBao, 2));
        //个人公积金
        mDataBinding.tvTaxKind1Gjj.setText(NumberUtils.format(retBean.personalGjj, 2));
        //个人所得税
        mDataBinding.tvTaxKind1Sds.setText(NumberUtils.format(retBean.personalIncomeTax, 2));
        //个人缴纳金额
        mDataBinding.tvTaxKind1Result2.setText(getString(R.string.personal_jl_amount) + getString(R.string.unit_yuan1) + ": " +
                NumberUtils.format(retBean.personalJlAmount, 2));
        //单位缴纳金额
        mDataBinding.tvTaxKind1Result3.setText(getString(R.string.company_jl_amount) + getString(R.string.unit_yuan1) + ": " +
                NumberUtils.format(retBean.companyJlAmount, 2));

        //明细
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        mDataBinding.rvAmount.setLayoutManager(layoutManager);
        TaxKind1RetAdapter adapter = new TaxKind1RetAdapter();
        adapter.setDatas(mViewModel.getWageRateRetList(this, retBean));
        mDataBinding.rvAmount.setAdapter(adapter);
    }
}